<template>
  <!-- LYB医技科室工作量表 -->
  <div>
    <h1>医技科室工作报表</h1>
    <h3>时期：{{dateList.dateBegin}} ~ {{dateList.dateEnd}}</h3>
    <el-table :data="tableData" :span-method="objectSpanMethod" stripe border style="width: 100%">
      <el-table-column prop="id" label="科别" width="120" align="center"></el-table-column>
      <el-table-column prop="name" label="项目" align="center"></el-table-column>
      <el-table-column prop="amount1" label="合计" align="center"></el-table-column>
      <el-table-column prop="amount2" label="科别" width="120" align="center"></el-table-column>
      <el-table-column prop="amount3" label="项目" align="center"></el-table-column>
      <el-table-column prop="amount4" label="合计" align="center"></el-table-column>
    </el-table>
  </div>
</template>

<script>
import {} from "@/api";
import { showOkMsg, showErrorMsg } from "@/utils/index.js";

export default {
  data() {
    return {
      tableData: [
        {
          id: "放射科",
          name: "小计",
          amount1: "234",
          amount2: "B超室",
          amount3: "小计",
          amount4: ""
        },
        {
          id: "12987123",
          name: "照片",
          amount1: "165",
          amount2: "4.43",
          amount3: "彩色B超",
          amount4: 10
        },
        {
          id: "12987124",
          name: "透视",
          amount1: "324",
          amount2: "1.9",
          amount3: "",
          amount4: 10
        },
        {
          id: "12987125",
          name: "排粪照影",
          amount1: "621",
          amount2: "心电图室",
          amount3: "小计",
          amount4: 10
        },
        {
          id: "12987126",
          name: "造影",
          amount1: "539",
          amount2: "4.1",
          amount3: "心电图十二导",
          amount4: 10
        },
        {
          id: "12987125",
          name: "吞钡",
          amount1: "621",
          amount2: "2.2",
          amount3: "",
          amount4: 10
        },
        {
          id: "12987126",
          name: "运输",
          amount1: "539",
          amount2: "胃肠镜室",
          amount3: "小计",
          amount4: 10
        },
        {
          id: "检验科",
          name: "王小虎",
          amount1: "621",
          amount2: "2.2",
          amount3: "微波治疗",
          amount4: 10
        },
        {
          id: "12987126",
          name: "王小虎",
          amount1: "539",
          amount2: "4.1",
          amount3: "胃镜",
          amount4: 10
        },
        {
          id: "12987125",
          name: "王小虎",
          amount1: "621",
          amount2: "2.2",
          amount3: "肠镜",
          amount4: 10
        },
        {
          id: "12987126",
          name: "王小虎",
          amount1: "539",
          amount2: "CT室",
          amount3: "小计",
          amount4: 10
        },
        {
          id: "12987125",
          name: "王小虎",
          amount1: "621",
          amount2: "",
          amount3: "体部",
          amount4: 10
        },
        {
          id: "12987126",
          name: "王小虎",
          amount1: "539",
          amount2: "4.1",
          amount3: "头部",
          amount4: 10
        },
        {
          id: "12987125",
          name: "王小虎",
          amount1: "621",
          amount2: "2.2",
          amount3: "其它",
          amount4: 10
        },
        {
          id: "12987126",
          name: "王小虎",
          amount1: "539",
          amount2: "放疗室",
          amount3: "小计",
          amount4: 10
        },
        {
          id: "12987125",
          name: "王小虎",
          amount1: "621",
          amount2: "2.2",
          amount3: "直线加速器",
          amount4: 10
        },
        {
          id: "12987126",
          name: "王小虎",
          amount1: "539",
          amount2: "4.1",
          amount3: "",
          amount4: 10
        },
        {
          id: "12987125",
          name: "王小虎",
          amount1: "621",
          amount2: "核医学",
          amount3: "小计",
          amount4: 10
        },
        {
          id: "12987126",
          name: "王小虎",
          amount1: "539",
          amount2: "4.1",
          amount3: "核素检查",
          amount4: 10
        },
        {
          id: "12987125",
          name: "王小虎",
          amount1: "621",
          amount2: "2.2",
          amount3: "贴敷治疗",
          amount4: 10
        },
        {
          id: "12987126",
          name: "王小虎",
          amount1: "539",
          amount2: "4.1",
          amount3: "核素治疗",
          amount4: 10
        },
        {
          id: "12987125",
          name: "王小虎",
          amount1: "621",
          amount2: "",
          amount3: "",
          amount4: ""
        },
        {
          id: "12987126",
          name: "王小虎",
          amount1: "539",
          amount2: "",
          amount3: "",
          amount4: ""
        },
        {
          id: "12987125",
          name: "王小虎",
          amount1: "621",
          amount2: "",
          amount3: "",
          amount4: ""
        },
        {
          id: "12987126",
          name: "王小虎",
          amount1: "539",
          amount2: "",
          amount3: "",
          amount4: ""
        },
        {
          id: "12987125",
          name: "王小虎",
          amount1: "621",
          amount2: "",
          amount3: "",
          amount4: ""
        }
      ],
      column_row_offset: {
        id: [7, 19],
        name: [],
        amount1: [],
        amount2: [3, 3, 4, 4, 3, 4],
        amount3: [],
        amount4: []
      },
      now_col_row_num: {},
      now_col_offset: {},
      total: 0
    };
  },
  created() {
    this.getTableList(this.dateList.dateBegin, this.dateList.dateEnd);
  },
  mounted() {
    this.algorithm();
  },
  props: ["dateList"],
  methods: {
    algorithm() {
      this.column_row_offset.id.forEach(els => {
        this.total += els;
      });
      for (let i = 0; i <= this.total; i++) {
        this.column_row_offset.name.push(1);
        this.column_row_offset.amount1.push(1);
        this.column_row_offset.amount2.push(1);
        this.column_row_offset.amount3.push(1);
        this.column_row_offset.amount4.push(1);
      }
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (!this.now_col_row_num[column.property]) {
        this.now_col_row_num[column.property] = Object.assign(
          [],
          this.column_row_offset[column.property]
        );
        let a = this.now_col_row_num[column.property].shift();
        this.now_col_offset[column.property] = a;
        return {
          rowspan: a,
          colspan: 1
        };
      } else if (rowIndex >= this.now_col_offset[column.property]) {
        let a = this.now_col_row_num[column.property].shift();
        this.now_col_offset[column.property] += a;
        return {
          rowspan: a,
          colspan: 1
        };
      } else {
        return {
          rowspan: 0,
          colspan: 0
        };
      }
    },
    getTableList() {
      if (this.dateList.dateBegin && this.dateList.dateEnd) {
        inpatientWorkload({
          kb: this.dateList.administrative,
          startTime: this.dateList.dateBegin,
          endTime: this.dateList.dateEnd
        }).then(res => {
          if (res.code === 0) {
            showOkMsg(res.msg);
            this.tableData = res.data;
          }
        });
      } else {
        showErrorMsg("请选择开始或结束日期");
      }
    }
  }
};
</script>

<style scoped>
h1 {
  font-size: 24px;
  text-align: center;
  padding: 23px 0;
}
h3 {
  text-align: center;
  padding-bottom: 20px;
}
h2 {
  padding: 4px 0;
  display: flex;
  justify-content: space-between;
}
</style>